import React, { useEffect, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import "../../../styles/EditIssue.scss";
import { Form, Button, Input, message } from "antd";
import { patch_list } from "../../../utils/api/index";
interface Props {}
function EditIssue(props: Props) {
  var location = useLocation();
  var navigate = useNavigate();
  var [data, setData] = useState([]);
  useEffect(() => {
    setData(location.state);
  }, []);
  // console.log(data);
  const [form] = Form.useForm();
  useEffect(() => {
    form.setFieldsValue({
      id: location.state.id,
      key: location.state.key,
      danhao: location.state.danhao,
      renyuan: location.state.renyuan,
      cangku: location.state.cangku,
      time: location.state.time,
      shenheren: location.state.shenheren,
      shenhetime: location.state.shenhetime,
      zhuangtai: location.state.zhuangtai,
    });
  }, [data]);
  //编辑
  const onFinish = (values: any) => {
    patch_list(values).then((res) => {
      console.log(res.data);
      if (res.request.status == 200) {
        message.open({ type: "success", content: "编辑成功!" });
        navigate("/index/home/deposit/depositList");
      } else {
        message.open({ type: "error", content: "编辑失败!" });
      }
    });
  };
  const onFinishFailed = (errorInfo: any) => {
    console.log("Failed:", errorInfo);
  };
  let cancel = function () {
    navigate("/index/home/deposit/depositList");
  };
  return (
    <div className="editissue">
      <div className="head">仓储管理 / 出库管理 / 编辑出库</div>
      <div className="main">
        <div className="box">
          <Form
            form={form}
            name="basic"
            labelCol={{ span: 6 }}
            wrapperCol={{ span: 22 }}
            initialValues={{ remember: true }}
            onFinish={onFinish}
            onFinishFailed={onFinishFailed}
            autoComplete="off"
          >
            <Form.Item label="ID号" name="id" hidden>
              <Input />
            </Form.Item>
            <Form.Item label="出库单号" name="danhao">
              <Input />
            </Form.Item>
            <Form.Item label="出库人员" name="renyuan">
              <Input />
            </Form.Item>
            <Form.Item label="出库仓库" name="cangku">
              <Input />
            </Form.Item>
            <Form.Item label="申请出库时间" name="time">
              <Input />
            </Form.Item>
            <Form.Item label="审核人" name="shenheren">
              <Input />
            </Form.Item>
            <Form.Item label="审核时间" name="shenhetime">
              <Input />
            </Form.Item>
            <Form.Item label="状态" name="zhuangtai">
              <Input />
            </Form.Item>
            <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
              <Button className="btn" onClick={cancel}>
                取消
              </Button>
              <Button className="btn" type="primary" htmlType="submit">
                保存
              </Button>
            </Form.Item>
          </Form>
        </div>
      </div>
    </div>
  );
}

export default EditIssue;
